<template>
    <div class="jump">
      <div class="home_bg" v-if="bgshow"></div>
    </div>
</template>

<script>
  import {getuserinfo, login} from "../api/api";
    import aestool from '@/utils/aestool.js';
    export default {
        name: "jump",
      data(){
          return{
            bgshow: false
          }
      },
      methods:{
        getNum() {
          var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
          var nums = ""
          for (var i = 0; i < 16; i++) {
            var id = parseInt(Math.random() * 61);
            nums += chars[id];
          }
          return nums
        },
        onDetail() {
          if (!sessionStorage.getItem('token')) {
            if (this.$route.query.token) {
              alert(this.$route.query.token)
              let token = this.$route.query.token
              sessionStorage.setItem('token', token)
            } else {
              let str = this.getNum()
              let params = {
                queuedata: aestool.encrypt('login_begin', str),
                queuedata_s: aestool.encrypt(str, '123456asdzxlogin'),
              }
              login(params).then(res => {
                this.bgshow = false
                if (res.Status == 200) {
                  let link = aestool.decrypt(res.Data, 'Login81432258700')
                  console.log('授权', link)
                  window.location.href = link
                } else {
                  this.bgshow = true
                }
              }).catch(res => {
                this.bgshow = true
              })
            }
          }
        },
        //获取用户信息
        getUserData(){
          getuserinfo().then(res => {
            if (res.data.Status == 200) {
              sessionStorage.setItem('useinfo', aestool.decrypt(res.data.Data, '123456asdzxcqwe0'))
            }
          })
        },
      },
      created() {
          this.onDetail()
          this.getUserData()
      }
    }
</script>

<style>
   .jump{
     width:200px;
     height:200px;
     position: absolute;
     top:50%;
     margin-left:-100px;
     margin-top:-100px;
     left:50%;
     background:url("../assets/1200x1200.jpg");
     background-size:100% 100%;
   }
</style>
